﻿using TouchFish.Timer;
using UnityEngine;

public class TestTimer : MonoBehaviour
{
    public Timer timer;
    public string TimerName = "TestTimer";

    private void OnGUI()
    {
        if (GUILayout.Button("开启定时"))
        {
            if (!TimerDriver.Exist(timer))
            {
                timer = TimerDriver.AddTimer(5, TimerName).OnUpdated((v) =>
                {
                    Debug.Log("Timer Update");
                }).OnCompleted(
                   () =>
                   {
                       Debug.Log("Timer OnCompleted");
                   }
                );
                Debug.Log("当前设定时间为：" + timer.Duration);
            }
        }

        if (GUILayout.Button("定时2秒"))
        {
            if (TimerDriver.Exist(TimerName))
            {
                TimerDriver.GetTimer("12138").SetTime(2);
                Debug.Log("当前设定时间为：" + timer.Duration);
            }
        }
        if (GUILayout.Button("定时-2秒"))
        {
            if (TimerDriver.Exist(TimerName))
            {
                TimerDriver.GetTimer("12138").SetTime(-2);
                Debug.Log("当前设定时间为：" + timer.Duration);
            }
        }
        if (GUILayout.Button("定时10秒"))
        {
            if (null != timer)
            {
                timer.SetTime(10);
                Debug.Log("当前设定时间为：" + timer.Duration);
            }
        }
    }
}